package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLeveVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NursingLevelServiceImpl implements NursingLevelService {
    @Autowired
    private NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLeveVo> listAll() {
        List<NursingLeveVo> nursingLevels = nursingLevelMapper.listAll();
        return nursingLevels;
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public NursingLeveVo getById(Long id) {
        NursingLevel nursingLevel = nursingLevelMapper.getById(id);
        return  BeanUtil.copyProperties(nursingLevel, NursingLeveVo.class);
    }

    @Override
    public void deleteById(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void updateStatus(Long id, Integer status) {
 nursingLevelMapper.isEnable(id, status);
    }

    @Override
    public PageResponse selectByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        //设置分页
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingLeveVo> nursingLeveVos = nursingLevelMapper.selectByPage(name, status);
        return PageResponse.of(nursingLeveVos,NursingLeveVo.class);
    }

    /**
     * 新增护理项目
     * @param nursingLevelDto
     */
    @Override
    public void add(NursingLevelDto nursingLevelDto) {
NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto,NursingLevel.class);
nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = BeanUtil.toBean(nursingLevelDto,NursingLevel.class);
        nursingLevelMapper.updateById(nursingLevel);
    }




}
